package com.zjp.blog.base;

import com.zjp.blog.data.model.Config;
import com.zjp.blog.utils.Logging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import java.util.*;

/**
 * @author pj_zhong
 * @email pj_zhong@163.com / pj_zhong@gmail.com
 */

@Component
public class ApplicationContext {

    private Map<String,Config> systemConfigs;

    @Autowired
    private ServletContext servletContext;

    public  ServletContext getServletContext() {
        return servletContext;
    }

    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    public Map<String, Config> getSystemConfigs() {
        return systemConfigs;
    }

    public  void setSystemConfigs(List<Config> configs) {
        systemConfigs = new HashMap<String, Config>();

        for(Config config : configs){
            Logging.info(config.toString());
            systemConfigs.put(config.getKey(),config);
            getServletContext().setAttribute(config.getKey(),config.getValue());
        }
    }
}
